"""
多项式模型
1.先将多项式模型通过特征扩展器转为线性模型
2.交给线性模型处理
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sklearn.linear_model as lm
import sklearn.preprocessing as sp
import sklearn.pipeline as pl

data = pd.read_csv('Salary_Data.csv')

train_x = data.iloc[:,:-1]
train_y = data.iloc[:,-1]

model = pl.make_pipeline(sp.PolynomialFeatures(3),
                         lm.LinearRegression())

model.fit(train_x,train_y)

pred_train_y = model.predict(train_x)

#模型可视化
plt.scatter(train_x,train_y,color='dodgerblue',s=50)
plt.plot(train_x,pred_train_y,color='orangered')
plt.show()